<?php
define("rowsPerPage", 10);
class Paging
{
	var $rowPerPage;
	var $Url;
	var $Css;
	
	var $nav;
	var $prev;
	var $next;
	var $first;
	var $last;
	var $curPage;
	
	var $arrNum;
	
	var $rowCount;
	
	public function setPage($rowperpage, $url, $css)
	{
		$this->rowPerPage = $rowperpage;
		$this->Url = $url;
		$this->Css = $css;
	}
	
	public function getPaging($arrObject, $page)
	{
		$this->curPage = $page;
		$beg = ($page - 1) * 10;
		$end = ($page * $this->rowPerPage) - 1;
		$this->rowCount = count($arrObject);
		
		if ($this->rowCount == 0)
			return null;
		
		if ($end > $this->rowCount - 1)
			$end = $this->rowCount -1;
			
		$arr;
		$j = 0;
		for ($i=$beg; $i<=$end; $i=$i+1)
		{
			$this->arrNum[$j] = $i + 1;
			$arr[$j] = $arrObject[$i];
			$j = $j + 1;
		}
		
		return $arr;
	}
	
	public function setNavigate()
	{
		$maxPage = ceil($this->rowCount/$this->rowPerPage);
		$navi = "";
		
		for ($i=1; $i<=$maxPage; $i=$i+1)
		{
			if ($i == $this->curPage)
				$navi .= "$i";
			else 
				$navi .= "<a href=\"$this->Url?page=$i\" class=\"$this->Css\">&nbsp;" . $i . "&nbsp;</a>";
		}
		$this->nav = $navi;
		if ($this->curPage > 1)
		{
			$page = $this->curPage - 1;
			
			$tmp = "<a href=\"" .$this->Url . "?page=" . $page . "\" class=\"$this->Css\" > Trang trÆ°á»›c </a>";
			$this->prev = $tmp;
			$tmp = "<a href=\"" .$this->Url . "?page=1\" class=\"$this->Css\" > Trang Ä‘áº§u </a>";
			$this->first = $tmp;
		}
		else 
		{
			$this->prev = '&nbsp;';
			$this->first = '&nbsp;';
		}
		
		
		if ($pageNum < $maxPage)
		{
			$page = $pageNum + 1;
			$next = " <a href=\"$this->Url?page=$page\" class=\"$this->Css\"> Trang káº¿ </a> ";
			$this->next = $next;
			$last = " <a href=\"$this->Url?page=$maxPage\" class=\"$this->Css\"> Trang cuá»‘i </a> ";
			$this->last = $last;
		}
		else
		{
			$this->next = '&nbsp;';
			$this->last = '&nbsp;';
		}
	}
	
	public function getNav()
	{
		return $this->nav;
	}
	
	public function getFirst()
	{
		return $this->first;
	}
	
	public function getNext()
	{
		return $this->next;
	}
	
	public function getPrev()
	{
		return $this->prev;
	}
	
	public function getLast()
	{
		return $this->last;
	}
	
	public function getArrayNum()
	{
		return $this->arrNum;
	}
}

?>